package com.bite.Queue;

import java.util.concurrent.TimeUnit;

public class ProdCostModel {
    public static void main(String[] args) throws InterruptedException {
        MyBlockingQueue myBlockingQueue = new MyBlockingQueue(100);

        Thread customer = new Thread(() -> {
            while (true) {
                try {
                    int value = myBlockingQueue.deQueue();
                    System.out.println("消费了一个 " + value);
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"消费者");



        Thread producer = new Thread(() -> {
            int ret = 0;
            while (true) {
                try {
                    myBlockingQueue.enQueue(ret);
                    System.out.println("生产了一个 " + ret);
                    ret++;
                    TimeUnit.MILLISECONDS.sleep(10);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        },"生产者");

        producer.start();
        customer.start();
        customer.join();
        producer.join();
    }


}
